package com.lykj.llw.box.ui.fragment

import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.lifecycle.lifecycleScope
import com.gyf.immersionbar.BarHide
import com.gyf.immersionbar.ImmersionBar
import com.lykj.lib_base.app.BaseApplication
import com.lykj.lib_base.base.BaseFragment
import com.lykj.lib_base.bus.FlowBus
import com.lykj.lib_base.constants.BConstants
import com.lykj.lib_base.internal.extfun.clickWithTrigger
import com.lykj.lib_base.internal.utils.ToastUtils
import com.lykj.llw.box.databinding.FrgTradingBinding
import com.lykj.llw.box.ui.activity.MobileLoginActivity
import com.lykj.llw.box.ui.activity.RecyclingSmallAccountActivity
import com.lykj.llw.box.ui.activity.RoleBuyActivity
import com.lykj.llw.box.ui.activity.SaleSmallAccountActivity

/**
 * ================================================
 * Frag-交易
 * ================================================
 *
 * @author gosha
 * @date 2023/10/12-18:20
 */
class TradingFragment : BaseFragment() {
    lateinit var binding: FrgTradingBinding
    var isInit = false

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        binding = FrgTradingBinding.inflate(layoutInflater)
        initUI()
        initData()
        setListener()
        return binding.root
    }

    override fun onResume() {
        ImmersionBar.with(this).transparentBar()
            .statusBarDarkFont(true) //状态栏字体是深色，不写默认为亮色
            .navigationBarDarkIcon(true)
            .hideBar(BarHide.FLAG_HIDE_NAVIGATION_BAR)
            .navigationBarEnable(false)
            .init()
        super.onResume()

        if (!isInit) {
            isInit = true
//            obtainTrading()
        }
    }

    override fun initUI() {
        if (!BConstants.isDebug) {
            binding.ivLucyLeak.visibility = View.GONE
        }
    }

    override fun initData() {
    }

    override fun setListener() {
        binding.ivSaleSmallXh.clickWithTrigger {
            if (BaseApplication.instance?.getUserInfo()?.token.isNullOrBlank()) {
                FlowBus.with<Int>(BConstants.BUS_KEY.HOME_SWITCH_NAV_OTHER)
                    .post(lifecycleScope, 2)
                startActivity(Intent(requireContext(), MobileLoginActivity::class.java))
            } else {
                startActivity(Intent(requireContext(), SaleSmallAccountActivity::class.java))
            }
        }
        binding.ivBuyRole.clickWithTrigger {
            startActivity(Intent(requireContext(), RoleBuyActivity::class.java))
        }
        binding.ivRecycleXh.clickWithTrigger {
            if (BaseApplication.instance?.getUserInfo()?.token.isNullOrBlank()) {
                FlowBus.with<Int>(BConstants.BUS_KEY.HOME_SWITCH_NAV_OTHER)
                    .post(lifecycleScope, 2)
                startActivity(Intent(requireContext(), MobileLoginActivity::class.java))
            } else {
                startActivity(Intent(requireContext(), RecyclingSmallAccountActivity::class.java))
            }
        }
        binding.ivLucyLeak.clickWithTrigger {
            ToastUtils.showShort(requireContext(), "超值捡漏")
        }
    }

    override fun onDestroy() {
        super.onDestroy()
    }
}